﻿using Ebusiness_OrderService.Services;
using Ebusiness_ProductService.Services;
using Ebusiness_WebSites.Services.Dtos;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Servicecomb.Saga.Omega.Abstractions.Transaction;
using Volo.Abp.AspNetCore.Mvc;

namespace Ebusiness_WebSites.Controllers
{
    [Route("OrderProduct/[action]")]
    [ApiController]
    public class OrderProductController : AbpController
    {
        public IOrderService orderService { get; set; }

        public IProductService productService { get; set; }

        public OrderProductController()
        {

        }


        /// <summary>
        /// 分布式事务
        /// </summary>
        /// <param name="addProductOrderDto"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        //[SagaStart] // 开始使用Servceicomb-pack。启动
        public string AddProductOrder(AddProductOrderDto addProductOrderDto)
        {

            var productdto = productService.CreateAsync(addProductOrderDto.productDto).Result;

            var orderdto = orderService.CreateAsync(addProductOrderDto.orderDto).Result;

            throw new Exception("添加订单和商品成功后，返回出现异常");

            return "添加成功";
        }
    }
}
